package org.gikolet.util;

import java.io.IOException;
import java.io.InputStream;

public class ReadBytesStreamWrapper extends InputStream {

	private InputStream in;
	private long readBytes;

	public ReadBytesStreamWrapper(InputStream in) {
		this.readBytes = 0;
		this.in = in;
	}

	public long getReadLength() {
		return readBytes;
	}

	@Override
	public int read() throws IOException {
		int readBytes = this.in.read();
		if (readBytes != -1) {
			this.readBytes += readBytes;
		}
		return readBytes;
	}

	@Override
	public int read(byte[] b) throws IOException {
		int readBytes = this.in.read(b);
		if (readBytes != -1) {
			this.readBytes += readBytes;
		}
		return readBytes;
	}

	@Override
	public int read(byte[] b, int off, int len) throws IOException {
		int readBytes = this.in.read(b, off, len);
		if (readBytes != -1) {
			this.readBytes += readBytes;
		}
		return readBytes;
	}

	@Override
	public void close() throws IOException {
		this.in.close();
	}
}
